package com.azdebugit.atom.test;


import org.mapstruct.ap.shaded.freemarker.template.utility.DateUtil;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class Main {
    public static void main(String[] args) {
        Long timeStamp = System.currentTimeMillis();  //获取当前时间戳
        System.out.println("----" + timeStamp);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String sd = sdf.format(new Date(Long.parseLong(String.valueOf(timeStamp))));      // 时间戳转换成时间
        System.out.println("格式化结果：" + sd);

        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy 年 MM 月 dd 日 HH 时 mm 分 ss 秒");
        String sd2 = sdf2.format(new Date(Long.parseLong(String.valueOf(timeStamp))));
        LocalDate parse = LocalDate.parse("2020-11-19 12:12:12", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

//        Long leftTime = timeStamp- LocalDateTime.parse("2020-11-19 12:12:12").format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        System.out.println("格式化结果：" + sd2);

        System.out.println("#############"+getLeftTime(1639L));
    }

    private static String getLeftTime(Long totalSeconds) {
        long day = 0;
        long hour = 0;
        long minute = 0;
        long second = 0;
        if (totalSeconds > 0) {
            second = totalSeconds;
            if (second >= 60) {
                minute = second / 60;
                second = second % 60;
                if (minute >= 60) {
                    hour = minute / 60;
                    minute = minute % 60;
                    if (hour > 24) {
                        day = hour / 24;
                        hour = hour % 24;
                    }
                }
            }
        }

        return day + "天" + hour + "小时" + minute + "分钟" + second + "秒";
    }

}